package com.ibeetl.admin.core.util;

import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * MD5加密组件
 * 
 * @author linnt
 * @version 1.0
 */
public abstract class MD5Coder {

	/*
	 * 对字符串使用md5加密
	 */
	public static String getMD5Char(String pswStr) {
		String digestedPwdString = "";
		if (!pswStr.equals("")) {
			try {
				MessageDigest messageDigest = MessageDigest.getInstance("MD5");
				messageDigest.update(pswStr.getBytes());
				digestedPwdString = bytes2Hex(messageDigest.digest());
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
		return digestedPwdString;
	}

	
	private static String bytes2Hex(byte[] bts) {
		String des = "";
		String tmp = null;
		for (int i = 0; i < bts.length; i++) {
			tmp = (Integer.toHexString(bts[i] & 0xFF));
			if (tmp.length() == 1) {
				des += "0";
			}
			des += tmp;
		}
		return des;
	}


	public static void main(String[] args) throws Exception {
		//设置日期格式
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm");
		//对方系统时间
		String dateStr = df.format(new Date());
		String ss = MD5Coder.getMD5Char(MD5Coder.getMD5Char("jwrcfw")+"18613197393"+dateStr);
		System.out.println(ss);
		System.out.println(MD5Coder.getMD5Char("jwrcfw"));
		System.out.println("http://127.0.0.1:8080/login.do?dateData="+dateStr + "&username=18613197393&checkData="+ss);
	}
}
